import { createHashRouter, Navigate } from 'react-router-dom'
import { useSelector } from 'react-redux'
import { getCookies } from '@/libs/storage'
// import { useLocation } from 'react-router-dom'
// 引入Layout框架页面
import Layout from '@/Layout'

import Login from '@/views/LoginPage'
import HomePage from '@/views/HomePage'
import TodoPage from '@/views/TodoPage'
import MessagePage from '@/views/MessagePage'
import PersonalCenterPage from '@/views/PersonalCenterPage'

import CyjsPage from '@/views/TodoPage/CyjsPage'
import FyPage from '@/views/TodoPage/FyPage'
export const routers = [
	{
		path: '/login',
		element: <Login />
	},
	{
		path: '/',
		element: <Layout />,
		children: [
			{ path: '/home', element: <HomePage /> },

			{ path: '/todo', element: <TodoPage /> },
			{ path: '/cyjs', element: <CyjsPage /> },
			{ path: '/fy', element: <FyPage /> },

			{ path: '/message', element: <MessagePage /> },
			{ path: '/personalCenter', element: <PersonalCenterPage /> },

			// 如果URL没有"#路由"，跳转Home页面
			{ path: '/', element: <Navigate to="/home" /> },
		]
	}
]

export const globalRouters = createHashRouter(routers)

// 路由守卫
export function PrivateRoute (props) {
	const token = useSelector(state => state.user.token) || getCookies()
	return token ? props.children : <Navigate to="/" />
	// return props.children
}
